// Pipit 标准库最终版头文件
// 专为Pipit核心集成设计

#ifndef PIPIT_STDLIB_FINAL_H
#define PIPIT_STDLIB_FINAL_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <time.h>

// 版本信息
#define PIPIT_STDLIB_VERSION "2.0.0"

// 基础数据结构

typedef struct {
    char** tokens;
    int count;
} pipit_string_split_t;

typedef struct {
    long size;
    int is_directory;
    int is_regular_file;
    long last_modified;
} pipit_file_info_t;

typedef struct {
    void** items;
    int count;
    int capacity;
} pipit_array_t;

typedef struct {
    char** keys;
    char** values;
    int count;
    int capacity;
} pipit_map_t;

// ================== 字符串模块 ==================

// 基础操作
int pipit_strlen(const char* s);
char* pipit_string_concat(const char* s1, const char* s2);
char* pipit_string_repeat(const char* s, int count);
char* pipit_string_substring(const char* s, int start, int end);
int pipit_string_find(const char* s, const char* substr);
int pipit_string_starts_with(const char* s, const char* prefix);
int pipit_string_ends_with(const char* s, const char* suffix);
char* pipit_string_replace(const char* s, const char* old, const char* new);
char* pipit_string_trim(char* s);
void pipit_string_to_upper(char* s);
void pipit_string_to_lower(char* s);
pipit_string_split_t pipit_string_split(const char* s, const char* delimiter);
void pipit_string_split_free(pipit_string_split_t* split);
char* pipit_string_format(const char* format, ...);

// ================== 数学模块 ==================

// 基础运算
int pipit_add(int a, int b);
int pipit_subtract(int a, int b);
int pipit_multiply(int a, int b);
int pipit_divide(int a, int b);
int pipit_modulo(int a, int b);

// 高级运算
double pipit_power(double base, double exponent);
double pipit_sqrt(double x);
double pipit_abs_double(double x);
int pipit_abs(int x);
int pipit_max(int a, int b);
int pipit_min(int a, int b);
int pipit_round(double x);
int pipit_floor(double x);
int pipit_ceil(double x);

// 三角函数
double pipit_sin(double x);
double pipit_cos(double x);
double pipit_tan(double x);

// 数论
int pipit_is_prime(int n);
long long pipit_factorial(int n);
int pipit_gcd(int a, int b);
int pipit_fibonacci(int n);

// 随机数
int pipit_random();
void pipit_srand(unsigned int seed);
int pipit_random_range(int min, int max);

// ================== IO模块 ==================

// 文件操作
int pipit_file_exists(const char* filename);
char* pipit_read_file(const char* filename);
int pipit_write_file(const char* filename, const char* content);
int pipit_append_file(const char* filename, const char* content);
long pipit_get_file_size(const char* filename);
int pipit_get_file_info(const char* filename, pipit_file_info_t* info);

// 目录操作
int pipit_create_directory(const char* path);
int pipit_directory_exists(const char* path);
char** pipit_list_directory(const char* path, int* count);
void pipit_list_directory_free(char** list, int count);

// 路径操作
char* pipit_get_current_directory();
char* pipit_join_path(const char* path1, const char* path2);

// ================== 集合模块 ==================

// 动态数组
pipit_array_t* pipit_array_create();
void pipit_array_destroy(pipit_array_t* array);
int pipit_array_add(pipit_array_t* array, void* item);
void* pipit_array_get(pipit_array_t* array, int index);
int pipit_array_size(pipit_array_t* array);
void pipit_array_clear(pipit_array_t* array);

// 哈希映射
pipit_map_t* pipit_map_create();
void pipit_map_destroy(pipit_map_t* map);
int pipit_map_set(pipit_map_t* map, const char* key, const char* value);
const char* pipit_map_get(pipit_map_t* map, const char* key);
int pipit_map_size(pipit_map_t* map);
int pipit_map_has_key(pipit_map_t* map, const char* key);
void pipit_map_clear(pipit_map_t* map);

// ================== 日期时间模块 ==================

long pipit_time_now();
long pipit_time_millis();
char* pipit_time_format(long timestamp, const char* format);
long pipit_time_add_days(long timestamp, int days);
int pipit_time_diff_days(long t1, long t2);

// ================== 工具函数 ==================

void* pipit_malloc(size_t size);
void* pipit_calloc(size_t count, size_t size);
void* pipit_realloc(void* ptr, size_t size);
void pipit_free(void* ptr);
void pipit_debug_log(const char* message);

#ifdef __cplusplus
}
#endif

#endif // PIPIT_STDLIB_FINAL_H